import request from "@/utils/request";


// 定义 UserInfo 类型
interface UserInfo {
    id: number,
    name: string,
    age: number,
    address: string
}

// 每个请求的泛型类型是用于约束 返回的数据类型，如：AxiosResponse<UserInfo>

// 获取用户信息。请求格式为 GET /api/getUserInfo?id=xxx
export const getUserInfo = async (params: any) => {
    return await request.get<UserInfo[]>(
        '/api/getUserInfo',
        {
            params: params
        }
    )
}

// 新增用户信息。请求格式为 POST /api/insertUserInfo
export const insertUserInfo = async (data: UserInfo) => {
    return await request.post<UserInfo>(
        '/api/insertUserInfo',
        data
    )
}

// 更新用户信息。请求格式为 PUT /api/updateUserInfo
export const updateUserInfo = async (data: any) => {
    return await request.put<UserInfo>(
        '/api/updateUserInfo',
        data
    )
}

// 删除用户信息。请求格式为 DELETE /api/deleteUserInfo?id=xxx
export const deleteUserInfo = (params: any) => {
    return request.delete(
        '/api/deleteUserInfo',
        {
            params: params
        }
    )
}

const test = async () => {
    const res = await getUserInfo({ id: 1 })
    let data = res.data;
    data.forEach(item => {
        console.log(item.id, item.name, item.age, item.address)
    })
    let status = res.status;
    console.log(status)
    let statusText = res.statusText;
    console.log(statusText)
    let headers = res.headers;
    console.log(headers)
}

